package com.inspur.dao.impl;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.util.ArrayList;
import java.util.List;

import javax.sql.DataSource;

import org.springframework.beans.factory.annotation.Autowired;

import com.inspur.base.BaseJDBCDao;
import com.inspur.base.SystemConstant;
import com.inspur.dao.TestDao;
import com.inspur.entity.TestEntity;
public class TestDaoImpl extends BaseJDBCDao implements TestDao{
    @Autowired
    private DataSource dataSource;
    @Override
    public List<TestEntity> selectAllFriend() {
        Connection conn = null;
        PreparedStatement pstmt = null;
        ResultSet rs = null;
        List<TestEntity> list=new ArrayList<TestEntity>();
        TestEntity testEntity=new TestEntity();
        try {
            conn = dataSource.getConnection();
            StringBuilder tempSql = new StringBuilder();
            tempSql.append(SystemConstant.SELECT_ALL_FRIEND);
            pstmt = conn.prepareStatement(tempSql.toString());
            rs = pstmt.executeQuery();
            
            while(rs.next()) {
                testEntity.setId(rs.getInt("id"));
                testEntity.setUname(rs.getString("uname"));
            }
        } catch (Exception e) {
            list=new ArrayList<TestEntity>();
            System.out.println(e.getMessage());
        } finally {
            this.closeAllConnection(conn, pstmt, rs);
        }
        return list;
    }

}
